<template>
    <div>
        <HomeNav :index="'0'"></HomeNav>
        这是详情页
        <router-link to="/detail11">11</router-link>
        <router-link to="/detail14">14</router-link>
        <router-link to="/detail17">17</router-link>
        <!-- {{$route.params}} -->
        <button @click="add">添加购物车</button>
    </div>
</template>

<script>
import HomeNav from "../components/Home/HomeNav.vue";
export default {
    components: { HomeNav },
    async created() {
        let data = await this.$API.DetailAPI.GetDetailId(this.$route.params);
        // console.log(data);
    },
    beforeRouteUpdate(to, from, next) {
        // ...
        console.log(to);
        next();
    },
    beforeRouteEnter(to, from, next) {
        // ...
        console.log(to);
        next();
    },
    methods: {
        async add() {
            console.log(this.$route.params);
            console.log({ token: localStorage.token });
            console.log({ ...this.$route.params, token: localStorage.token });
            let data = await this.$API.DetailAPI.GetAddCart({
                token: localStorage.token,
                ...this.$route.params,
            });
            if (data.code==1) {
                this.open()
            }
        },
        open() {
            this.$alert("添加成功", "恭喜您！！", {
                confirmButtonText: "确定",
                callback: (action) => {
                    this.$message({
                        type: "info",
                        message: `action: ${action}`,
                    });
                },
            });
        },
    },
};
</script>

<style>
</style>